-- @owner: wang-tianjing1
-- @date: 2024/8/19
-- @testpoint: before--truncate在表上支持行级触发器，使用show triggers查询

@conn PrimaryDbBmode;
--step1:创建表 except:成功
create table test_trigger_src_tb0012(id1 int, id2 int, id3 int);
insert into test_trigger_src_tb0012 values(100,200,300);
create table test_trigger_des_tb0012(id1 int, id2 int, id3 int);
insert into test_trigger_des_tb0012 values(1,2,3);

--step2:创建触发器函数 except:成功
create or replace function tri_truncate_func0012() returns trigger as
$$
declare
begin truncate table test_trigger_des_tb0012;
return new;
end
$$ language plpgsql;
/

--step3:创建触发器 except:成功
create trigger truncate_trigger0012 before truncate on test_trigger_src_tb0012
for each statement execute procedure tri_truncate_func0012();
/

--step4:执行触发事件 except:成功
truncate table test_trigger_src_tb0012;
select * from test_trigger_src_tb0012;

--step5:检查触发结果 except:成功
select * from test_trigger_des_tb0012;

--step6:查询触发器，添加where条件 except:成功
show triggers from public where "Event"='TRUNCATE';

--step7:查询触发器，添加like条件 except:成功
show triggers from public where "Event" like 'TRUNCATE';

--step8:清理环境 except:成功
drop trigger if exists truncate_trigger0012 on test_trigger_src_tb0012;
drop function tri_truncate_func0012() cascade;
drop table test_trigger_src_tb0012;
drop table test_trigger_des_tb0012;